home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / driverss.zip / PKTRING.ASM < prev    next >
Assembly Source File  |  1991-01-29  |  11KB  |  566 lines

  1. version    equ    0
  2. ;History:232,1
  3.  
  4. ;  Russell Nelson, Clarkson University.  December 24, 1989
  5. ;  Copyright, 1989, Russell Nelson
  6.  
  7. ;   This program is free software; you can redistribute it and/or modify
  8. ;   it under the terms of the GNU General Public License as published by
  9. ;   the Free Software Foundation, version 1.
  10. ;
  11. ;   This program is distributed in the hope that it will be useful,
  12. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;   GNU General Public License for more details.
  15. ;
  16. ;   You should have received a copy of the GNU General Public License
  17. ;   along with this program; if not, write to the Free Software
  18. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     include    defs.asm
  21.  
  22. code    segment word public
  23.     assume    cs:code, ds:code
  24.  
  25.     org    80h
  26. phd_dioa    label    byte
  27.  
  28.     org    100h
  29. start:
  30.     jmp    start_1
  31.  
  32. copyleft_msg    label    byte
  33.  db "Packet ringer version ",'0'+majver,".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  34.  db "This program is free software; see the file COPYING for details.",CR,LF
  35.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  36. crlf_msg    db    CR,LF,'$'
  37.  
  38. int_pkt    macro    num
  39.     pushf
  40.     cli
  41.     call    their_isr_&num
  42.     endm
  43.  
  44. their_isr_1    dd    ?
  45. their_isr_2    dd    ?
  46. packet_int_1    db    ?,?,?,?
  47. packet_int_2    db    ?,?,?,?
  48. send_count    dw    RUNT
  49. handle        dw    ?
  50. transmit_count    dw    ?
  51. receive_count    dw    ?
  52. packet_mode    dw    ?
  53. this_mode    dw    ?
  54.  
  55. signature    db    'PKT DRVR',0
  56. signature_len    equ    $-signature
  57.  
  58. no_signature_msg    db    "No packet driver at that address",'$'
  59. usage_msg    db    "usage: pktring [-m] <packet_int_1> <packet_int_2>",'$'
  60. sending_msg    db    "Sending from ",'$'
  61. to_msg        db    " to ",'$'
  62.  
  63. not_implemented    db    "xx ",'$'
  64. current_mode    db    "-> ",'$'
  65. two_spaces    db    "   ",'$'
  66.  
  67. test_modes    db    ?        ;nonzero if we should test the modes.
  68.  
  69. mode_names    dw    mode_1_msg,mode_2_msg,mode_3_msg,mode_4_msg
  70.         dw    mode_5_msg,mode_6_msg
  71.  
  72. mode_1_msg    db    "1) Turn off receiver",'$'
  73. mode_2_msg    db    "2) Receive only packets sent to this interface",'$'
  74. mode_3_msg    db    "3) Mode 2 plus broadcast",'$'
  75. mode_4_msg    db    "4) Mode 3 plus limited multicast",'$'
  76. mode_5_msg    db    "5) Mode 3 plus all multicast",'$'
  77. mode_6_msg    db    "6) All packets",'$'
  78.  
  79. mode_code    dw    mode_1_tester,mode_2_tester,mode_3_tester,mode_4_tester
  80.         dw    mode_5_tester,mode_6_tester
  81.  
  82. mode_good_msg    db    " passed",CR,LF,'$'
  83. mode_bad_msg    db    " FAILED!",7,CR,LF,'$'
  84.  
  85. usage_error:
  86.     mov    dx,offset usage_msg
  87. error:
  88.     mov    ah,9
  89.     int    21h
  90.     int    20h
  91.  
  92. start_1:
  93.     cld
  94.  
  95.     mov    dx,offset copyleft_msg
  96.     mov    ah,9
  97.     int    21h
  98.  
  99.     mov    si,offset phd_dioa+1
  100.     cmp    byte ptr [si],CR    ;end of line?
  101.     je    usage_error
  102.  
  103. another_switch:
  104.     call    skip_blanks
  105.  
  106.     cmp    al,'-'            ;did they specify a switch?
  107.     jne    not_switch
  108.     cmp    byte ptr [si+1],'m'    ;did they specify '-m'?
  109.     je    got_mode_switch
  110.     jmp    usage_error        ;no, must be an error.
  111. got_mode_switch:
  112.     mov    test_modes,1
  113.     add    si,2
  114.     jmp    another_switch
  115.  
  116. not_switch:
  117.     mov    di,offset packet_int_1
  118.     call    get_number
  119.     mov    di,offset packet_int_2
  120.     call    get_number
  121.  
  122.     call    skip_blanks        ;check for the end of the line.
  123.     cmp    al,CR
  124.     jne    usage_error
  125.  
  126.     mov    sp,offset start        ;now that we're finished with
  127.                     ;the parameters, put our stack there.
  128.  
  129.     mov    ah,35h            ;get their packet interrupt.
  130.     mov    al,packet_int_1
  131.     int    21h
  132.     mov    their_isr_1.offs,bx
  133.     mov    their_isr_1.segm,es
  134.  
  135.     lea    di,3[bx]
  136.     mov    si,offset signature
  137.     mov    cx,signature_len
  138.     repe    cmpsb
  139.     je    signature_1_ok
  140.     jmp    no_signature_err
  141. signature_1_ok:
  142.  
  143.     mov    ah,35h            ;get their packet interrupt.
  144.     mov    al,packet_int_2
  145.     int    21h
  146.     mov    their_isr_2.offs,bx
  147.     mov    their_isr_2.segm,es
  148.  
  149.     lea    di,3[bx]
  150.     mov    si,offset signature
  151.     mov    cx,signature_len
  152.     repe    cmpsb
  153.     je    signature_2_ok
  154.     jmp    no_signature_err
  155. signature_2_ok:
  156.  
  157.     mov    dx,offset sending_msg
  158.     mov    ah,9
  159.     int    21h
  160.  
  161.     push    ds
  162.     mov    ax,1ffh            ;driver_info
  163.     int_pkt    2
  164.     jc    saying_2_1
  165.     pushf
  166. saying_2:
  167.     lodsb
  168.     call    chrout
  169.     cmp    byte ptr ds:[si],0
  170.     jne    saying_2
  171.  
  172.     popf
  173. saying_2_1:
  174.     pop    ds
  175.     call    fatal_error
  176.  
  177.     mov    dx,offset to_msg
  178.     mov    ah,9
  179.     int    21h
  180.  
  181.     push    ds
  182.     mov    ax,1ffh            ;driver_info
  183.     int_pkt    1
  184.     jc    saying_1_1
  185.     pushf
  186.     push    ax
  187. saying_1:
  188.     lodsb
  189.     call    chrout
  190.     cmp    byte ptr ds:[si],0
  191.     jne    saying_1
  192.  
  193.     pop    ax
  194.     popf
  195. saying_1_1:
  196.     pop    ds
  197.     call    fatal_error
  198.  
  199.     push    ax
  200.     push    dx
  201.     mov    dx,offset crlf_msg
  202.     mov    ah,9
  203.     int    21h
  204.     pop    dx
  205.     pop    ax
  206.  
  207.     mov    ah,2            ;access all packets.
  208.     mov    al,ch            ;their class from driver_info().
  209.     mov    bx,dx            ;their type from driver_info().
  210.     mov    dl,cl            ;their number from driver_info().
  211.     mov    cx,0            ;type length of zero.
  212.     push    cs            ;es:di -> our receiver.
  213.     pop    es
  214.     mov    di,offset our_recv
  215.     int_pkt    1
  216.     call    fatal_error
  217.     mov    handle,ax
  218.  
  219.     cmp    test_modes,0        ;should we test the receive modes?
  220.     je    get_their_address    ;no.
  221.  
  222.     mov    ah,21            ;get the receive mode.
  223.     mov    bx,handle
  224.     int_pkt    1
  225.     jc    bad_1
  226.     mov    packet_mode,ax
  227.  
  228.     mov    this_mode,1        ;start trying with mode 1.
  229. try_mode:
  230.     cmp    this_mode,4        ;skip modes 4 and 5 (don't work yet).
  231.     jne    try_mode_1
  232.     mov    this_mode,6
  233. try_mode_1:
  234.     cmp    this_mode,6        ;have we hit the last mode?
  235.     ja    no_more_modes        ;yes.
  236.  
  237.     mov    ah,20            ;set the receive mode.
  238.     mov    bx,handle
  239.     mov    cx,this_mode
  240.     int_pkt    1
  241.     jc    tried_mode        ;we tried it, and it didn't work.
  242.  
  243.     mov    bx,this_mode        ;print the name of this mode.
  244.     shl    bx,1
  245.     mov    ah,9
  246.     mov    dx,mode_names[bx-2]
  247.     int    21h
  248.  
  249.     mov    bx,this_mode        ;do the test for this mode.
  250.     shl    bx,1
  251.     call    mode_code[bx-2]
  252.     mov    dx,offset mode_good_msg    ;report success.
  253.     jnc    mode_good
  254.     mov    dx,offset mode_bad_msg    ;report failure.
  255. mode_good:
  256.     mov    ah,9
  257.     int    21h
  258.  
  259. tried_mode:
  260.  
  261.     inc    this_mode        ;try the next mode.
  262.     jmp    try_mode
  263.  
  264. no_more_modes:
  265.  
  266.     mov    ah,20            ;set the receive mode.
  267.     mov    bx,handle
  268.     mov    cx,packet_mode
  269.     int_pkt    1
  270. bad_1:
  271.     jnc    get_their_address
  272.     jmp    bad
  273.  
  274. get_their_address:
  275.  
  276.     mov    ah,6            ;get the destination's address.
  277.     mov    bx,handle
  278.     mov    cx,EADDR_LEN
  279.     push    cs            ;es:di -> to address.
  280.     pop    es
  281.     mov    di,offset our_buffer
  282.     int_pkt    1
  283.     jc    bad_1
  284.  
  285. wait_for_key:
  286.     inc    send_count
  287.     cmp    send_count,GIANT    ;too big?
  288.     jbe    length_ok
  289.     mov    transmit_count,0    ;zero the counts.
  290.     mov    receive_count,0
  291.     mov    send_count,RUNT        ;yes, reset it back down again.
  292. length_ok:
  293.  
  294.     mov    cx,send_count
  295.     call    send_packet
  296.     jc    bad
  297.  
  298.     inc    transmit_count
  299.  
  300.     mov    ax,transmit_count
  301.     call    wordout
  302.  
  303.     mov    al,' '
  304.     call    chrout
  305.  
  306.     mov    ax,receive_count
  307.     call    wordout
  308.  
  309.     mov    al,CR
  310.     call    chrout
  311.  
  312.     mov    ah,1            ;check for any key.
  313.     int    16h
  314.     je    wait_for_key        ;no key -- keep waiting.
  315.  
  316.     mov    ah,0            ;read a key.
  317.     int    16h
  318.  
  319.     mov    ah,3            ;release the handle.
  320.     mov    bx,handle
  321.     int_pkt    1
  322.     jc    bad
  323.  
  324.     int    20h
  325.  
  326. all_done:
  327.     xor    bx,bx            ;only release the handle once.
  328.     xchg    bx,handle
  329.     or    bx,bx
  330.     je    all_done_1        ;we've already released it.
  331.     mov    ah,3            ;release_type
  332.     int_pkt    1
  333.     jc    bad
  334. all_done_1:
  335.     int    20h
  336.  
  337. bad:
  338.     call    print_error
  339. okay:
  340.     jmp    all_done
  341.  
  342.  
  343. no_signature_err:
  344.     mov    dx,offset no_signature_msg
  345.     mov    ah,9
  346.     int    21h
  347.     int    20h
  348.  
  349.  
  350.     assume    ds:nothing
  351. our_recv:
  352.     or    ax,ax            ;first or second call?
  353.     jne    our_recv_1        ;second -- we ignore the packet
  354.     push    cs
  355.     pop    es
  356.     mov    di,offset our_buffer + GIANT
  357.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  358. our_recv_1:
  359.     add    si,EADDR_LEN+EADDR_LEN
  360.     lodsw
  361.     mov    cx,ax
  362.     sub    cx,EADDR_LEN+EADDR_LEN+2
  363. our_recv_2:
  364.     lodsb
  365.     cmp    al,cl
  366.     loope    our_recv_2
  367.     jne    our_recv_3        ;if they don't match, don't increment the count.
  368.     inc    receive_count
  369. our_recv_3:
  370.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  371.  
  372. ;two macros to return an error code.
  373.  
  374. rz    macro
  375.     stc
  376.     jne    $+3
  377.     ret
  378.     endm
  379.  
  380. rnz    macro
  381.     stc
  382.     je    $+3
  383.     ret
  384.     endm
  385.  
  386. mode_1_tester:
  387.     call    send_bcast        ;don't receive broadcast,
  388.     rnz
  389.     call    send_to_them        ;don't receive their address,
  390.     rnz
  391.     call    send_random        ;don't receive other addresses,
  392.     rnz
  393.     call    send_multi        ;don't receive multicasts.
  394.     rnz
  395.     clc
  396.     ret
  397. mode_2_tester:
  398.     call    send_bcast        ;don't receive broadcast,
  399.     rnz
  400.     call    send_random        ;don't receive other addresses,
  401.     rnz
  402.     call    send_multi        ;don't receive multicasts.
  403.     rnz
  404.     call    send_to_them        ;do    receive their address,
  405.     rz
  406.     clc
  407.     ret
  408. mode_3_tester:
  409.     call    send_bcast        ;do    receive broadcast,
  410.     rz
  411.     call    send_random        ;don't receive other addresses,
  412.     rnz
  413.     call    send_multi        ;don't receive multicasts.
  414.     rnz
  415.     call    send_to_them        ;do    receive their address,
  416.     rz
  417.     clc
  418.     ret
  419. mode_4_tester:
  420. ;;; set up 01:01:01:01:01:01 in the multicast list.
  421.     call    send_bcast        ;do    receive broadcast,
  422.     rz
  423.     call    send_random        ;don't receive other addresses,
  424.     rnz
  425.     call    send_multi        ;do    receive multicasts.
  426.     rz
  427.     call    send_to_them        ;do    receive their address,
  428.     rz
  429.     clc
  430.     ret
  431. mode_5_tester:
  432. ;;; set up an empty mullticast list.
  433.     call    send_bcast        ;do    receive broadcast,
  434.     rz
  435.     call    send_random        ;don't receive other addresses,
  436.     rnz
  437.     call    send_multi        ;do    receive multicasts.
  438.     rz
  439.     call    send_to_them        ;do    receive their address,
  440.     rz
  441.     clc
  442.     ret
  443. mode_6_tester:
  444.     call    send_bcast        ;do    receive broadcast,
  445.     rz
  446.     call    send_random        ;do    receive other addresses,
  447.     rz
  448.     call    send_multi        ;do    receive multicasts.
  449.     rz
  450.     call    send_to_them        ;do    receive their address,
  451.     rz
  452.     clc
  453.     ret
  454.  
  455. send_bcast:
  456.     mov    dl,'B'
  457.     mov    ah,6
  458.     int    21h
  459.     mov    al,0ffh            ;all-ones is broadcast.
  460.     jmp    short send_fixed_addr
  461. send_random:
  462.     mov    dl,'R'
  463.     mov    ah,6
  464.     int    21h
  465.     mov    al,002h            ;all twos is an okay address.
  466.     jmp    short send_fixed_addr
  467. send_multi:
  468.     mov    dl,'M'
  469.     mov    ah,6
  470.     int    21h
  471.     mov    al,001h            ;first bit set is multicast.
  472. send_fixed_addr:
  473.     push    cs
  474.     pop    es
  475.     mov    di,offset our_buffer
  476.     mov    cx,EADDR_LEN
  477.     rep    stosb
  478.     jmp    short send_to_addr
  479. send_to_them:
  480.     mov    dl,'T'
  481.     mov    ah,6
  482.     int    21h
  483.  
  484.     mov    ah,6            ;get the destination's address.
  485.     mov    bx,handle
  486.     mov    cx,EADDR_LEN
  487.     push    cs            ;es:di -> to address.
  488.     pop    es
  489.     mov    di,offset our_buffer
  490.     int_pkt    1
  491.     jnc    send_to_addr
  492. send_to_addr_bad:
  493.     jmp    bad
  494. send_to_addr:
  495. ;send the packet in our_buffer.
  496. ;return zr if we didn't receive it, and ne if we did.
  497.  
  498. ;we'll know we got a packet if the receive count gets bumped.
  499.     mov    receive_count,0
  500.  
  501.     mov    cx,100
  502.     call    send_packet
  503.     jc    send_to_addr_3
  504.  
  505.     mov    ax,2
  506.     call    set_timeout
  507. send_to_addr_1:
  508.     cmp    receive_count,0        ;did we receive it?
  509.     jne    send_to_addr_2
  510.     call    do_timeout
  511.     jne    send_to_addr_1
  512.     mov    dl,'0'
  513.     mov    ah,6
  514.     int    21h
  515.     xor    al,al
  516.     ret
  517. send_to_addr_2:
  518.     mov    dl,'1'
  519.     mov    ah,6
  520.     int    21h
  521.     or    sp,sp
  522.     ret
  523. send_to_addr_3:
  524.     xor    al,al
  525.     ret
  526.  
  527.  
  528. send_packet:
  529. ;enter with cx = length of packet.
  530. ;stuff the standard contents into our_buffer.
  531. ;return the results of sending the packet.
  532.     push    cx
  533.  
  534.     push    cs            ;es:di -> our buffer.
  535.     pop    es
  536.     mov    di,offset our_buffer+EADDR_LEN+EADDR_LEN
  537.     mov    ax,cx
  538.     stosw
  539.     sub    cx,EADDR_LEN+EADDR_LEN+2
  540. send_packet_1:
  541.     mov    al,cl
  542.     stosb
  543.     loop    send_packet_1
  544.  
  545.     pop    cx
  546.  
  547.     mov    ah,4            ;send_pkt
  548.     mov    si,offset our_buffer    ;ds:si -> buffer.
  549.     int_pkt    2
  550.     ret
  551.  
  552.  
  553.     include    timeout.asm
  554.     include    pkterr.asm
  555.     include    getnum.asm
  556.     include    getdig.asm
  557.     include    skipblk.asm
  558.     include    chrout.asm
  559.     include    digout.asm
  560.  
  561. our_buffer    label    byte
  562.  
  563. code    ends
  564.  
  565.     end    start
  566.